/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package epibot.testeProteinas;

import epibot.BancoDeDados.ArmazenaDados.Fasta;
import epibot.BancoDeDados.ArmazenaDados.ProcessaFasta;
import java.io.File;
import java.util.ArrayList;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;

/**
 *
 * @author Rafael Tosta
 */
class ImportProteinasTeste extends Thread {

    private JPanelTesteProteinas jp;

    public ImportProteinasTeste(JPanelTesteProteinas jp) {
        this.jp = jp;
    }

    @Override
    public void run() {
        JFileChooser e = new JFileChooser();
        e.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
        File file = null;
        int returnVal = e.showOpenDialog(jp);
        if (returnVal == JFileChooser.APPROVE_OPTION) { //se escolhido o diretório...
            file = e.getSelectedFile();
        }

        if (file != null) {
            this.jp.setPath(file.getAbsolutePath());
            jp.getjTextSequencias().setText("");
            jp.setFastas(null);

            jp.getjTextSequencias().setEditable(false);
            jp.getjPanelLoadFiles().setVisible(true);

            //obtem os arquivos fasta em um array
            ProcessaFasta ex = new ProcessaFasta();
            ArrayList<Fasta> fastas = ex.go(file, this.jp);

            if (!fastas.isEmpty()) {
                //atribue a variavel do JPanelTesteProteinas
                jp.setFastas(fastas);
                jp.getjTextSequencias().setText(ex.getArquivoTextoFasta(fastas));
                jp.getjTextInformations().append("\n\n -> " + fastas.size() + " proteins selected");

            } else {
                JOptionPane.showMessageDialog(jp, "Import aborted, incompatible file!");
                jp.setFastas(null);
                jp.getjTextSequencias().setEditable(true);
                this.jp.setPath("");
            }

            jp.getjPanelLoadFiles().setVisible(false);
        }
    }
}
